/**
 * use case
 * <span> {{ xxx | momentFormat: 'YYYY-MM-DD' }}
 * the format from moment
 * https://momentjs.com/
 */

import { Pipe, PipeTransform } from '@angular/core';
import * as moment from 'moment';

@Pipe({
    name: 'momentFormat'
})
export class MomentFormatPipe implements PipeTransform {
    transform(value: string, format: string): string {
        const m = moment(value);
        const isValidDate = m.isValid();
        return isValidDate ? m.format(format) : 'Invalid Date';
    }
}
